package com.bristua.barcode.customer.biz;

import com.bristua.barcode.common.util.DateUtils;
import com.bristua.barcode.common.util.HttpSessionUtil;
import com.bristua.barcode.common.util.SequenceUtil;
import com.bristua.barcode.customer.dao.TCustomerBankMapper;
import com.bristua.barcode.customer.dao.TCustomerMapper;
import com.bristua.barcode.customer.model.TCustomer;
import com.bristua.barcode.customer.model.TCustomerBank;
import com.bristua.barcode.customer.model.condition.AddCustomerBankParams;
import com.bristua.barcode.customer.model.condition.TCustomerExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2019/8/25.
 */
@Service
@Transactional
public class AddCustomerBankBiz {
    
    @Autowired
    private HttpSessionUtil httpSessionUtil;

    @Resource
    private TCustomerBankMapper tCustomerBankMapper;

    @Resource
    private TCustomerMapper tCustomerMapper;

    public void addCustomerBank(AddCustomerBankParams addCustomerBankParams){
        String userId = httpSessionUtil.getUserId();
        TCustomerBank tCustomerBank = new TCustomerBank();
        tCustomerBank.setBankId(SequenceUtil.nextId());
        tCustomerBank.setBankName(addCustomerBankParams.getBankName());
        tCustomerBank.setBankNo(addCustomerBankParams.getBankNo());
        tCustomerBank.setCreateTime(DateUtils.getShowDateTime());
        tCustomerBank.setRealName(addCustomerBankParams.getRealName());

        TCustomerExample tCustomerExample = new TCustomerExample();
        tCustomerExample.createCriteria().andCustomerNoEqualTo(userId);

        List<TCustomer> tCustomers = tCustomerMapper.selectByExample(tCustomerExample);
        if(tCustomers!=null && tCustomers.size()>0){
            tCustomerBank.setCustomerId(tCustomers.get(0).getCustomerId());
        }
        tCustomerBank.setStatus(1);
        tCustomerBankMapper.insert(tCustomerBank);
    }
}
